package com.huashi.dealer.modular.controller.store.market;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huashi.dealer.commonEntity.Goods;
import com.huashi.dealer.core.page.PageFactory;
import com.huashi.dealer.core.pojo.CommonResult;
import com.huashi.dealer.modular.business.goods.param.GiftGoodsListParam;
import com.huashi.dealer.modular.business.goods.param.GiftGoodsSaveParam;
import com.huashi.dealer.modular.business.goods.param.GiftGoodsStatusParam;
import com.huashi.dealer.modular.business.goods.service.GiftGoodsService;
import com.huashi.dealer.modular.business.goods.vo.GiftGoodsVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "Store端赠品商品管理")
@RestController("storeMarketGiftGoodsController")
@RequestMapping("/store/market/goods")
@Validated
public class GiftGoodsController {

    @Resource
    private GiftGoodsService giftGoodsService;

    @GetMapping("/list")
    @Operation(summary = "获取赠品商品分页列表")
    public CommonResult<Page<GiftGoodsVo>> getGiftGoodsList(GiftGoodsListParam param) {
        Page<Goods> page = PageFactory.defaultPage();
        Page<GiftGoodsVo> result = giftGoodsService.getGiftGoodsList(param, page);
        return CommonResult.data(result);
    }

    @PostMapping("/save")
    @Operation(summary = "新增或编辑赠品商品")
    public CommonResult<String> saveGoods(@RequestBody GiftGoodsSaveParam param) {
        giftGoodsService.saveOrUpdateGoods(param);
        return CommonResult.ok("操作成功");
    }

    @GetMapping("/delete/{goodsId}")
    @Operation(summary = "删除赠品商品")
    public CommonResult<String> deleteGoods(@PathVariable Long goodsId) {
        giftGoodsService.deleteGoods(goodsId);
        return CommonResult.ok("删除成功");
    }

    @GetMapping("/detail/{goodsId}")
    @Operation(summary = "获取赠品商品详情")
    public CommonResult<GiftGoodsVo> getGoodsDetail(@PathVariable Long goodsId) {
        GiftGoodsVo detail = giftGoodsService.getGoodsDetail(goodsId);
        return CommonResult.data(detail);
    }

    @PostMapping("/status")
    @Operation(summary = "更新商品状态")
    public CommonResult<String> updateGoodsStatus(@RequestBody GiftGoodsStatusParam param) {
        giftGoodsService.updateGoodsStatus(param.getGoodsId(), param.getStatus());
        return CommonResult.ok("操作成功");
    }

    @PostMapping("/copy/{goodsId}")
    @Operation(summary = "复制赠品商品")
    public CommonResult<String> copyGoods(@PathVariable Long goodsId) {
        giftGoodsService.copyGoods(goodsId);
        return CommonResult.ok("复制成功");
    }
}
